package org.example.alig;

import java.util.Arrays;
import java.util.List;

public class Alig3 {
    public static void main(String[] args) {
        Double x = 2.71;
        getW(x);
//        System.out.println(getW(x));
    }

    private static Double getW(Double x) {
        int m = x.intValue();
        List<Integer> ints = Arrays.asList(m - 1, m, m + 1);
        List<Double> doubles = Arrays.asList(0.49, 0.99);
        int zhengshu = 0;
        double yushu = 0;
        double sub_min = 1.0;
        for (Integer anInt : ints) {
            for (Double aDouble : doubles) {
                double value = anInt + aDouble;
                double sub = Math.abs(x - value);
                System.out.println(x + " - " + value + " = " + sub);
                if (sub < sub_min) {
                    sub_min = sub;
                    zhengshu = anInt;
                    yushu = aDouble;
                }
            }
        }
        return zhengshu + yushu;
    }
}
